Configuring the engine before launch

When initializing the component, by default, it will :

However, if this needs to be altered, it is possible to do some configuration work to better fit your needs. This tutorial will cover this aspect.

Through API

To drive the configuration through the API, some includes are required :

#include <NilkinsGraphics/Configurations/Configuration.h>

Now we have the possibility to prepare a configuration structure to pass during the component's initialization. Let's declare it :

nkGraphics::Configuration config ;

This structure will allow us to customize the run to some extent. Let's request it to start on DirectX11 rather than choosing automatically :

config.setWantedApi(nkGraphics::RENDERING_API::D3D11) ;
New log
We now start up the application using DirectX 11 !

Another important aspect of the configuration, covered here, is to set the ResourceManager's working path.
All components, when taking a path as a parameter, will take it relative to the working path. By default, the working path is set to be the execution path, from where the program has been launched.

However, it can be interesting to alter the working directory for the components to fetch their data in a subfolder, for instance. First include :

#include <NilkinsResources/ResourceManager.h>

And change the working path to be in a Data subfolder :

nkResources::ResourceManager::getInstance()->setWorkingPath("Data") ;

Now, when passing any path to the component, for instance to load a texture, it will always be implicitly relative to the working path. For instance, Textures/tex.jpg will be relative to Data.
This will make the component fetch the texture in Data/Textures/tex.jpg, relative to the execution folder.

Using the render contexts

As stated in the last tutorial, a RenderContext is a surface in which the engine can render to. There are various ways to render somewhere, during composition, but render contexts are the only way to render into a window and as such, to the screen.

First, let's get the right includes :

#include <NilkinsGraphics/RenderContexts/RenderContextDescriptor.h> #include <NilkinsGraphics/RenderContexts/RenderContextManager.h>

Let's create the context using them :

nkGraphics::RenderContextDescriptor contextDescriptor (1280, 1024, false, true) ; nkGraphics::RenderContext* context = nkGraphics::RenderContextManager::getInstance()->createRenderContext(contextDescriptor) ;

First, we need the configuration. The first two parameters are the surface dimensions, width and height, in pixels. Then come 2 booleans, to know whether the surface will be on-screen, and if vsync should be enabled.

A context can be either on-screen, or off-screen. Off-screen means that it will render to a texture, outside of any window. On-screen means that the surface will be attached to a window, which will display whatever is rendered into the context. In both cases, the underlying surface can be retrieved and read through the getBackBuffer() method.

Render contexts can be initialized in various ways. While this one creates the window or texture automatically, it is also possible to create a context and link it to an already existing window or texture.

And this concludes the configuration part ! You now have more tools to customize how the component boots and where it renders to.
In the next tutorials, we will finally learn how to get something on screen. Time for some serious business !